package com.xinwei.leetcode.每日一题;
// https://leetcode-cn.com/problems/day-of-the-week/
public class _1185_一周中的第几天 {
    // 以1970.12.31星期四为基点，算出所给日期与该日期差多少天
    public String dayOfTheWeek(int day, int month, int year) {
        int days = 0;
        int[] months = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30}; // 最后一个月不用
        String[] week = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"};
        // 年的贡献
        days = 365 * (year - 1971) + (year - 1969) / 4; // 这里因为1968是最近的闰年，所以减1969
        // 月的贡献
        for (int i = 0; i < month - 1; i++) { // 由于索引比月份是少1的，所以在<的基础上还要再减1
            days += months[i];
        }
        if (((year % 4 == 0 & year % 100 != 0) || year % 400 == 0) && month >= 3) {
            days++;
        }
        // 月中日的贡献
        days += day;

        return week[(days + 3) % 7];
    }
}
